#include "EndInsDestSendHandlerB.h"
#include "OriBodyRecvRelayHandler.h"
#include "InsRspHeaderRecvHandlerB.h"
#include "GlobalContext.h"

using namespace log4cplus;

Logger EndInsDestSendHandlerB::log=GetLogger(LOG4CPLUS_TEXT("EndInsDestSendHandlerB"));

ITransHandler* EndInsDestSendHandlerB::GetNextHandler()
{
	return new InsRspHeaderRecvHandlerB(m_oriRecvCount);
}

ITransHandler::ExecuteResultCode EndInsDestSendHandlerB::OnExecuteError(ClientContext &client,OVERLAPPED *ovl,ITransHandler::ExecuteResultCode executeResult)
{
	delete client.SetCurrentHandler(new OriBodyRecvRelayHandler());
	client.FreeInsteadContext();
	LOG4CPLUS_DEBUG_STR(log,LOG4CPLUS_TEXT("In EndSendB,try to send instead server's request data  failed(free instead context),try to retranslate original server receive data."));
	::PostQueuedCompletionStatus(GlobalContext::Instance().IOCP(),m_oriRecvCount,static_cast<ULONG_PTR>(client.SequenceNo()),client.OVL());
	return ITransHandler::ExecuteOK;
}